package gfxTest;

public class BBall extends Ball {
	
	private double velocity=0.001f;
	private double xvel=0.000f;
	private double acc=0.0000001f;
	
	public BBall(int x, int y) {
		super(x,y);
	}
	
	public void bounce() {	
		velocity += (acc);
		y += velocity;
		x += xvel;
		
		if(this.y+2*rad>=MainFrame.HEIGHT){
			y=MainFrame.HEIGHT-2*rad;
			velocity=-(velocity/1.2);
			if(Math.abs(velocity) < acc*2) velocity = 0.0f;
		}
		
		if(this.x+rad>=MainFrame.WIDTH || this.x-rad<=0){		
			xvel=-(xvel/1.05);
			x+=xvel;
		}
	}
	
	
	public boolean collides(BBall ball) {
		
		double dist;
		double xdist = this.x-ball.x;
		double ydist = this.y-ball.y;
		dist= Math.sqrt( Math.pow((xdist),2.0) + Math.pow((ydist), 2.0) );
		double bla = ((2*rad)-dist)/2;
		
		double tmpvel = Math.sqrt((xvel * xvel) + (velocity * velocity))/(1.2);
		
		if(Math.abs(velocity) < acc*2) velocity = 0.0f;
		if(Math.abs(xvel) < acc*2) xvel = 0.0f;
		
		if(dist<rad*2){
			
				this.x+=(xdist/dist)*bla;
				this.y+=(ydist/dist)*bla;
				//ball.x-=(xdist/dist)*bla;
				//ball.y-=(ydist/dist)*bla;
			
				xvel = (xdist/dist) * tmpvel;
				velocity = (ydist/dist) * tmpvel;
			
			return true;
		}
		else
			return false;
		
		
	}
}
